// 引入unocss css
import '@/plugins/unocss'

// 导入全局的svg图标
import '@/plugins/svgIcon'

// 多语言插件
import { setupI18n } from '@/plugins/vueI18n'

// 状态管理
import { setupStore } from '@/stores'

// 全局组件
import { setupGlobCom } from '@/components'

// 显示引入element-plus部分组件
import { setupElementPlus } from '@/plugins/elementPlus'

// 引入 form-create
import { setupFormCreate } from '@/plugins/formCreate'

// 引入全局样式
import '@/styles/index.scss'

// 引入动画
import '@/plugins/animate.css'

// 路由
import router, { setupRouter } from '@/router'

// 指令
import { setupDirectives } from '@/directives'

import { createApp } from 'vue'
import type { App as AppType } from 'vue'
import App from './App.vue'

// permission, 路由守卫
import '@/permission'

// 百度统计
import '@/plugins/tongji'

// console logger
import Logger from '@/utils/Logger'

// 解决v-html的安全隐患问题，v-html内容会经过过滤后插入，防止恶意代码执行，内置XSS防护
import VueDOMPurifyHTML from 'vue-dompurify-html'

export const setupGlobVar = (app: AppType<Element>) => {
  app.config.globalProperties.$s_file_url = s_file_url
}

const setupAll = async () => {
  const app = createApp(App)

  await setupI18n(app)

  setupStore(app)

  setupGlobCom(app)

  setupGlobVar(app)

  setupElementPlus(app)

  setupFormCreate(app)

  setupRouter(app)

  setupDirectives(app)

  // 等待路由器完成初始化
  await router.isReady()

  app.use(VueDOMPurifyHTML)

  if (process.env.NODE_ENV === 'production') {
    // 生成环境关闭devtools
    ;(app.config as any).devtools = false
  } else if (process.env.NODE_ENV === 'development') {
    app.config.performance = true
  }

  app.mount('#app')
}

setupAll()

Logger.prettyPrimary(`欢迎使用`, import.meta.env.VITE_APP_TITLE)
